package com.zzy.ware.service.impl;

import com.zzy.ware.entity.PurchaseEntity;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzy.utils.utils.PageUtils;
import com.zzy.utils.utils.Query;

import com.zzy.ware.mapper.PurchaseDetailMapper;
import com.zzy.ware.entity.PurchaseDetailEntity;
import com.zzy.ware.service.PurchaseDetailService;
import org.springframework.util.StringUtils;


@Service("purchaseDetailService")
public class PurchaseDetailServiceImpl extends ServiceImpl<PurchaseDetailMapper, PurchaseDetailEntity> implements PurchaseDetailService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
		/**
		 * status: 0
		 * wareId: 1
		 */
		QueryWrapper<PurchaseDetailEntity> wrapper = new QueryWrapper<>();
		String key = (String) params.get("key");
		if (!StringUtils.isEmpty(key)) {
			wrapper.and(w -> {
				w.eq("purchase_id", key).or().eq("sku_id", key);
			});
		}
		String status = (String) params.get("status");
		if (!StringUtils.isEmpty(status)) {
			wrapper.eq("status", status);
		}
		String wareId = (String) params.get("wareId");
		if (!StringUtils.isEmpty(wareId)) {
			wrapper.eq("ware_id", wareId);
		}
		IPage<PurchaseDetailEntity> page = this.page(new Query<PurchaseDetailEntity>().getPage(params),wrapper);

        return new PageUtils(page);
    }
	
	@Override
	public List<PurchaseDetailEntity> listDetailByPurchaseId(Long id) {
		List<PurchaseDetailEntity> entities = this.list(new QueryWrapper<PurchaseDetailEntity>()
				.eq("purchase_id", id));
		return entities;
		
	}
	
}











